
//Pinia类类似于VueX,有组合式API和选项式API两种写法
import {defineStore} from "pinia";
import {reqHospitalDepartment, reqHospitalDetail} from "@/api/hospital";
//引入详情类型的ts
import type {DepartmentResponseData, HospitalDetail,} from "@/api/hospital/type.ts";
//医院详情Pinia仓库存储类型
import type {DetailState} from "@/store/modules/interface/index.ts";
//
import type {HosPitalDetail} from "@/api/hospital/type.ts";

const useDetailStore = defineStore("Detail",{
    state: ():DetailState => {
        return {
            //存储医院详情的数据
            hospitalInfo: ({} as HosPitalDetail),
            departmentArr: [],
        }
    },
    actions: {
        //获取医院详情的方法
        async getHospital(hoscode: string) {
            let result: HospitalDetail = await reqHospitalDetail(hoscode);
            if (result.code === 200) {
                this.hospitalInfo = result.data;
            }
        },
        //获取医院科室数据的方法
        async getDepartment(hoscode: string) {
            let result:DepartmentResponseData = await reqHospitalDepartment(hoscode);
            if (result.code === 200) {
                this.departmentArr = result.data;
            }
        },
    },
    getters: {},
});

// 获取仓库的方法对外暴露
export default useDetailStore;
